import http from "@/utils/http/hub";
import { baseUrl } from "../../utils/env";

/**
 * 获取城市索引列表json文件
 */
export const getCityJson_ = (
  params,
  config = {
    custom: {
      auth: false,
      loading: false,
    },
  }
) => {
  return http.get({
    url: `/static/js/city.json`,
    params,
    config,
  });
};

/**
 * 获取城市索引列表json文件
 */
export const getCityJson__ = () => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: baseUrl + `/static/js/city.json`,
      header: {
        device: "mini",
      },
      success: (res) => {
        resolve(res);
      },
      fail(err) {
        reject(err);
      },
    });
  });
};

/**
 * 获取城市索引列表
 * tree 是否返回tree型结构0否1是
 * withLetter 是否带首字母0否1是
 */
export const getCityJson = (
  params = {},
  config = {
    custom: {
      loading: false,
    },
  }
) => {
  return http.get({
    url: `/utils/administrative`,
    params,
    config,
  });
};

/**
 * 获取配置
 */
export const getConfig = (
  params,
  config = {
    custom: {
      loading: false,
    },
  }
) => {
  return http.get({
    url: `/utils/config`,
    params,
    config,
  });
};

/**
 * 批量获取配置
 */
export const batchConfig = (
  params,
  config = {
    custom: {
      loading: false,
    },
  }
) => {
  return http.get({
    url: `/utils/batchConfig`,
    params,
    config,
  });
};

/**
 * 发送短信验证码
 * phone 手机号
 * type 类型login=登录bind=绑定forgetPwd=忘记密码modifyPwd=修改密码modifyOldPhone修改原手机号modifyNewPhone修改新手机号
 * from 来源user=用户端worker=保洁端
 */
export const smsSend = (
  params,
  config = {
    custom: {
      loading: true,
    },
  }
) => {
  return http.post({
    url: `/utils/smsSend`,
    params,
    config,
  });
};
